package cn.shadow.entity;

import cn.shadow.game.chess.Observer;
import cn.shadow.moulde.ISender;
import cn.shadow.proto.client.PlayerClientProtoContent.*;
import cn.shadow.proto.server.PlayerServerProtoContent.*;
import io.netty.buffer.ByteBuf;

/**
 * 玩家类
 */

public class Player extends PlayerBasic implements Observer {
    /**
     * 数据从数据库查询出来,查询数据库时，将数据填充进来
     *
     * @param proto
     */
    private ISender sender;

    public Player(PlayerServerProto proto, ISender sender) {
        super(proto.getBasic());
        this.sender = sender;
    }


    public PlayerServerProto encode4Server(long ctime) {
        PlayerServerProto.Builder builder = PlayerServerProto.newBuilder();
        builder.setBasic(encodeBasic4Server(ctime));
        return builder.build();
    }

    public PlayerClientProto encode4Client(long ctime) {
        PlayerClientProto.Builder builder = PlayerClientProto.newBuilder();
        builder.setBasic(encode4BasicClient());
        return builder.build();
    }

    public ISender getSender() {
        return sender;
    }

    public void setSender(ISender sender) {
        this.sender = sender;
    }


    @Override
    public void sendViewMsg(ByteBuf message) {
        sender.sendMessage(message);
    }
}
